<?

date_default_timezone_set('UTC');
$time = date("F j, Y, g:i:s a");

$errorfile = 'errors.txt';
$file = 'cronlogs.txt';

$dbhost = 'localhost';
$dbuser = 'domin';
$dbpass = 'andrei2011';

try{
	$conn = mysql_connect($dbhost, $dbuser, $dbpass);
	
	$dbname = 'domin_alpha1';
	mysql_select_db($dbname);
	
	$query = 'UPDATE user_stats set attack_points = attack_points + 1, wealth = wealth + income, turns_played = turns_played + 1';
	
	try{
		$result = mysql_query($query);
		$message = $time . " - Turn executed!\n";
		file_put_contents($file, $message, FILE_APPEND | LOCK_EX);
	}
	catch( Exception $e)	{
		$error = $time . 'There was an error: ' . $e;
		file_put_contents($errorfile, $error, FILE_APPEND | LOCK_EX);
	}
	
}
catch( Exception $e){
	$error = $time . 'There was an error: ' . $e;
	file_put_contents($errorfile, $error, FILE_APPEND | LOCK_EX);
}

